package beans;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.Min;

@Getter
@Setter
@NoArgsConstructor
public class PageQuery {

    @Min(value = 1, message = "当前页码不合法")
    private int page = 1;

    @Min(value = 1, message = "每页展示数量不合法")
    private int limit = 15;

    private int offset;

    public int getOffset() {
        return (page - 1) * limit;
    }

    public PageQuery(int page, int limit) {
        this.page = page;
        this.limit = limit;
        this.offset = (page - 1) * limit;
    }

    public PageQuery(int page) {
        this.page = page;
        this.limit = 10000;

    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }
}
